import fetch from "@/config/fetch"
import { my,img,poi,tps} from '@/config/env'


function getHeadPic(json){
  var flag = json.flag || "",
    custNum = json.custNum || "",
    sysPicNum = json.sysPicNum || "";
  switch(flag){
    case "100000000010":
//系统
      return img()+"/uimg/cmf/cust_headpic/0000000000_"+sysPicNum+"_120x120.jpg";
      break;
    case "100000000020":
// 自定义
      return img()+"/uimg/cmf/cust_headpic/"+$.md5(custNum+'msi_encrypt_salt')+"_00_60x60.jpg";
      break;
    default:
      return img()+"/uimg/cmf/cust_headpic/0000000000_01_60x60.jpg";
// 默认
  }
}


export default{
  state:{
    userinfo:undefined,
    yunzhuan:'',
    dianOrderStatus:false,
    volumeinfo: [],//优惠卷的信息
    realIndex:0//优惠券页面的
  },
  getters:{},
  mutations:{
    updateUserInfo(state,payload){
      state.userinfo = payload;
    },
    updateYunzhuan(state,payload){
      state.yunzhuan = payload;
    },
    updateDianOrderStatus(state,payload){
      state.dianOrderStatus = payload;
    },
    //优惠卷的信息
    updatevolumeInfo(state,payload){
      state.volumeinfo[0] = payload;
    }
  },
  actions:{
    getUserInfo({commit,state,dispatch}){

      let params = {};

      fetch({
        url: my + '/msi-web/api/member/queryMemberBaseInfo.do',
        params: params,
        // jsonp: 'callBack',
        // jsonpCallback:'getUserInfoFn'
      }).then((data) => {

        if(data.status == "success"){

          if(data.result && data.result.memberBaseInfo){
            data.result.memberBaseInfo.img = getHeadPic({
              flag:data.result.memberBaseInfo.sysHeadPicFlag,
              custNum:data.result.memberBaseInfo.custNum,
              sysPicNum:data.result.memberBaseInfo.sysHeadPicNum,
            })
            commit("updateUserInfo",data)
          }

        }

      });

      dispatch("getYunzhuan");

    },
    getYunzhuan({commit,state}){
      fetch({
        url: poi + '/cmwsmdm-web/member/queryPointJsonp.do',
        params: {},
      }).then((res) => {
        if (res && res.data && res.code == 0) {
            commit("updateYunzhuan",res.data.totalValue)
        }

      });
    }
    ,getOrderStatus({commit,state}){
      fetch({
        url: tps + '/app/orderCenter/queryIncompleteOrderList.do',
        params: {pageNumber:1,pageSize:10},
        jsonp:"callBack",
      }).then((res) => {
        if (res && res.data && res.code == 1) {
            if(res.data.totalCount > 0){
              commit("updateDianOrderStatus",true);
            }else{
              commit("updateDianOrderStatus",false);
            }
        }

      });
    },
    volumeInfo({commit,state}, options){//优惠卷的信息

       commit("updatevolumeInfo", options.data);

    },
    realIndex({commit,state}, options){//优惠卷的信息

       // commit("updatevolumeInfo", options.data);
       state.realIndex = options

    }
  }
}

